<template>
  <el-dialog
      title="详情"
      :visible.sync="dialogVisible"
      width="40%"
      @closed="closeCallBack"
      @opened="openCallBack"
      center>
    <el-row :gutter="20">
      <el-col :span="6">
        <div>
          <img :src="bookInfo.bookImgUrl" class="book-img">
        </div>
      </el-col>
      <el-col :span="18">
        <el-descriptions class="margin-top" title="图书详情" :column="3" size="medium" border>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-user"></i>
              书籍名称
            </template>
            {{ bookInfo.bookName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-mobile-phone"></i>
              作者
            </template>
            {{ bookInfo.author }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-location-outline"></i>
              ISBN
            </template>
            {{ bookInfo.isbn }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-tickets"></i>
              出版社
            </template>
            {{ bookInfo.press }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-office-building"></i>
              出版日期
            </template>
            {{ bookInfo.publishDate }}
          </el-descriptions-item>
        </el-descriptions>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import {queryBookDetail} from "@/api/book";

export default {
  name: "BookDetailDialog",
  data() {
    return {
      dialogVisible: false,
      bookInfo: {},
      bookId: null
    }
  },
  methods: {
    /**
     * 弹窗打开后回调
     */
    openCallBack() {
      if (this.bookInfo === null) {
        return false;
      }
      queryBookDetail({bookId:this.bookId}).then(res => {
        this.bookInfo = res.data;
      }).catch(error=>{
        console.error(error)
      })
    },
    closeCallBack() {
      this.bookInfo = {};
    }
  }
}
</script>

<style scoped>
.book-img {
  width: 100%;
  height: 100%;
}
</style>
